﻿$(function() {
    if ($(".register-body").length > 0) {
        register.init();
    }


});


var register= {
    init:function() {
        $("#userName,#userPwd,#vCode").keyup(function (event) {
            if ($("#register").length == 0) return;
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if (e && e.keyCode == 13) { // enter 键
                $("#register").focus();
                $("#register").click();
            }
        });

        $("#register").click(function() {
            var name = $("#userName").val().trim();
            var userPwd = $("#pwd").val().trim();
            var confirmPwd = $("#confirmPwd").val().trim();
            var userCode = $("#vCode").val().trim();
            if (isEmpty(name)) {
                alert("用户名不能为空");
                return false;
            }
            if (isEmpty(userPwd)) {
                alert("密码不能为空");
                return false;
            }
            if (isEmpty(userCode)) {
                alert("图形验证码不能为空");
                return false;
            }
            if (userPwd!=confirmPwd) {
                alert("两次密码不一致");
            }
            $.post("/register/", {
                    Pwd: userPwd,
                    UserName: name,
                    VCode: userCode,
                    '__RequestVerificationToken': $("input[name='__RequestVerificationToken']").val()
                },
                function(data) {

                    if (data.Status == 200) {
                        alert(data.Message);
                        window.location.href = "/login/";
                    } else {
                        alert(data.Message);
                    }

                });


        });
    }

}
